define(function (require) {
    var Base = require('group/common/main');
    var utils = require('common/utils/home');
    require('validate');
    require('idangerous');
    require('swipebox');
    require('tinyscrollbar');
    require('layer_ui');
    var Mask = require('common/mask');
    var mask = new Mask();

    return Base.extend({
        initialize: function (params) {
            var _this = this;
            Base.prototype.initialize.apply(this, [params]);
            if (_this['page_' + _global.a]) {
                _this['page_' + _global.a]();
            }
        },
        page_index: function () {

        },
        page_detail: function () {
            $('#messagea-input').on('click', function () {
                layer.open({
                    type: 1,
                    content: '<div class="messages-write"><textarea id="info"></textarea><div class="of-h"><span class="right"><input type="button" id="common_btn" value="发送"/></span></div></div>',
                    anim: 0,
                    style: 'position:fixed; bottom:0; left:0; width:100%;padding:0.4rem; border:none;'
                });
            });
            $('#common_btn').live('click', function () {
                var info = $('#info').val();
                if (info) {
                    var news_id = $('#news_id').val();
                    utils.ajaxPost(_.extend({'info': info, 'news_id': news_id}, {
                        m: 'index',
                        a: 'add_comment'
                    }), function (resp) {
                        mask.error(resp.msg);
                        location = location;
                    }, function (resp) {
                        mask.error(resp.msg);
                    });
                }
                else {
                    mask.error('填写评论内容');
                }
            });
            $('#favs').click(function () {
                var favs = $(this);
                var news_id = $('#news_id').val();
                utils.ajaxPost(_.extend({'news_id': news_id}, {m: 'index', a: 'favs'}), function (resp) {
                    console.log(resp);return;
                    if (resp.status == 1) {
                        mask.success('收藏成功');
                        favs.find('img').attr('src', _global.root + 'app/Tpl/news/public/images/new2_10.png');
                    }
                    else if (resp.status == 2) {
                        mask.success('取消成功');
                        favs.find('img').attr('src', _global.root + 'app/Tpl/news/public/images/new2_09.png');
                    }
                    else {
                        mask.error(resp.msg);
                    }
                }, function (resp) {
                    mask.error(resp.msg);
                });
            });
        },
        page_comment_list: function () {
            $('#messagea-input').on('click', function () {
                layer.open({
                    type: 1,
                    content: '<div class="messages-write"><textarea id="info"></textarea><div class="of-h"><span class="right"><input type="button" id="common_btn" value="发送"/></span></div></div>',
                    anim: 0,
                    style: 'position:fixed; bottom:0; left:0; width:100%;padding:0.4rem; border:none;'
                });
            });
            $('#common_btn').live('click', function () {
                var info = $('#info').val();
                if (info) {
                    var news_id = $('#news_id').val();
                    utils.ajaxPost(_.extend({'info': info, 'news_id': news_id}, {
                        m: 'index',
                        a: 'add_comment'
                    }), function (resp) {
                        mask.error(resp.msg);
                        location = location;
                    }, function (resp) {
                        mask.error(resp.msg);
                    });
                }
                else {
                    mask.error('填写评论内容');
                }
            });
        },
    });
});